package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysFileInfo;
import com.xx.job.mapper.SysFileInfoMapper;
import com.xx.job.service.system.SysFileInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFileInfo> implements SysFileInfoService {

    @Autowired
    private SysFileInfoMapper sysFileInfoMapper;

    @Override
    public int add(SysFileInfo sysFileInfo) {
        return sysFileInfoMapper.insert(sysFileInfo);
    }

    @Override
    public int delete(Long id) {
        return sysFileInfoMapper.deleteById(id);
    }

    @Override
    public int update(SysFileInfo sysFileInfo) {
        return sysFileInfoMapper.updateById(sysFileInfo);
    }

    @Override
    public SysFileInfo select(Long id) {
        return sysFileInfoMapper.selectById(id);
    }

    @Override
    public SysFileInfo selectBy(String UUIDPath) {
        QueryWrapper<SysFileInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("url",UUIDPath);
        return sysFileInfoMapper.selectOne(wrapper);
    }

    @Override
    public IPage<SysFileInfo> selectPage(PageDTO pageDTO, SysFileInfo sysFileInfo) {
        IPage<SysFileInfo> page = new Page<>(pageDTO.getPageIndex(),pageDTO.getPageSize());
        QueryWrapper<SysFileInfo> wrapper = new QueryWrapper<>();
        if(sysFileInfo.getPId() != null){
            wrapper.eq("p_id",sysFileInfo.getPId());
        }
        return sysFileInfoMapper.selectPage(page,wrapper);
    }
}
